package P3排序算法;

import java.util.Arrays;

//希尔排序 O(n^3/2)左右 S(1) 不稳定
public class ShellSort {
    public static void main(String[] args) {
        int[] arr = {9, 1, 4, 2, 3, 5, 8, 7, 6};
        sort(arr);
        System.out.println(Arrays.toString(arr));
    }

    public static void sort(int[] arr) {
        for (int gap = arr.length / 2; gap > 0; gap /= 2) {
            for (int i = gap; i < arr.length; i++) {
                for (int j = i; j - gap >= 0 && arr[j - gap] > arr[j]; j -= gap) {
                    Swap.swap(arr, j, j - gap);
                }
            }
        }
    }
}
